package rpc.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)//不序列化""||null属性
public class RpcObject {

    private RpcObject() {
    }

    private RpcObject(Boolean haveError, String errorMsg) {
        this.haveError = haveError;
        this.errorMsg = errorMsg;
    }

    private RpcObject(Boolean haveError, Object data) {
        this.haveError = haveError;
        this.data = data;
    }

    //0正常 1异常
    private Boolean haveError;

    //异常信息
    private String errorMsg;

    private Object data;

    public static RpcObject getSuccessInstance(Object data) {
        return new RpcObject(false,data);
    }

    public static RpcObject getErrorInstance(String errorMsg) {
        return new RpcObject(true,errorMsg);
    }

}
